package com.jyy.prefabricated.service;

import com.jyy.prefabricated.entity.FeedbackInfo;
import com.jyy.prefabricated.exception.CustomException;
import com.jyy.prefabricated.mapper.FeedbackInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @version 1.0.0
 * @author: zjj
 */
@Service
public class FeedbackInfoService {

    @Autowired
    private FeedbackInfoMapper feedbackInfoMapper;

    /**
     * 新增
     * @param feedbackInfo
     * @return
     */
    public int insert(FeedbackInfo feedbackInfo){
        feedbackInfoMapper.insert(feedbackInfo);
        return feedbackInfo.getId();
    }

    /**
     * 更新
     * @param feedbackInfo
     * @return
     */
    public int update(FeedbackInfo feedbackInfo){
        if(feedbackInfo.getId() == null){
            throw new CustomException("参数id不能为空");
        }
        return feedbackInfoMapper.updateByPrimaryKeySelective(feedbackInfo);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    public int delete(Integer id){
        return feedbackInfoMapper.deleteByPrimaryKey(id);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    public FeedbackInfo selectById(Integer id){
        return feedbackInfoMapper.selectByPrimaryKey(id);
    }

    /**
     * 根据参数查询列表
     * @param tel 联系电话
     * @param startDate 开始日期
     * @param endDate 结束日期
     * @return
     */
    public List<FeedbackInfo> selectByParams(String tel, String startDate, String endDate){
        return feedbackInfoMapper.selectByParams(tel, startDate, endDate);
    }
}
